import copy

import allure
import pytest
import requests

from VarRender import ReFresh
from core.global_text import g_varial
from extend.keywords import Keywords
from parse.CaseParser import case_parser
from parse.YamlCaseParser import readYamlAsList, read_context_put_global, load_yaml_files, yaml_case_parser


class TestRunner:
    # yaml_data = readYamlAsList(r"D:\huace_tech\inter_autotest02\day11\examples\yaml_testcase\01_login_yaml.yaml") # 读取单个
    # all_data = yaml_case_parser(r"D:\huace_tech\inter_autotest02\day11\examples\yaml_testcase")
    all_data = case_parser("excel",r"D:\huace_tech\PythonProject_repo\examples\excel_testcase")
    yaml_data = all_data["case_info"]
    @pytest.mark.parametrize("case_info", yaml_data)
    def test_case_execute(self,case_info):
        kw = Keywords()
        allure.dynamic.title(case_info["_case_name"])
        steps = case_info.get("step",None)
        local_context = case_info.get("context",{}) # 拿对应用例的ddt
        for step in steps:
            step_value = list(step.values())[0]
            context = copy.deepcopy(g_varial().show_dic())
            context.update(local_context) # 把ddt更新到context，再下一步进行渲染
            step_value = eval(ReFresh(step_value,context))
            key = step_value.get("关键字",None)
            kw_func = kw.__getattribute__(key)
            kw_func(**step_value)


if __name__ == '__main__':
    pytest.main(["-sv",__file__])
